/*
 * Copyright (C) 2011-2012 Adam Gregoire <bsdunx@gmail.com>
 * Copyright (C) 2011-2012 Jeff Hubbard <lord2800@gmail.com>
 *
 * This file is part of the ScriptKit scripting engine library.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#ifndef __SCRIPTKIT_HPP__
#define __SCRIPTKIT_HPP__ 1

// ScriptKit Public API

#include "config.hpp"

#include <string>
#include <cstdint>

#ifdef HAVE_STL_THREAD
#include <thread>
#else
#include <boost/thread.hpp>
#endif

#include "Exports.hpp"

//#include "jsapi.h"
//#include "jsapi_ext.hpp"
//#include "jsapi_ext_util.hpp"

namespace ScriptKit
{

class IScriptKit;

enum State : int32_t		// switch to enum class ASAP. GCC and VC 
							// both support this language extension.
{
	READY = 0x0,
	EXECUTING,
	PAUSED,
};

struct IScript
{
	struct Module
	{
		typedef void* moduledef_t;
	};
#ifdef HAVE_STL_THREAD
	std::thread thr;
#else
	boost::thread thr;
#endif
};

//template <typename T, typename enabled = void>
//struct Script { };

//template <typename T>
//struct Script<T, typename std::enable_if<std::is_same<T, IScript>::value>::type> : IScript { };

class IScriptKit
{
public:
	virtual IScript* CompileScript(std::string& fileName) = 0;
	virtual IScript* GetScript(std::string& fileName) = 0;
	virtual bool RunScript(IScript* script) = 0;
	virtual bool RegisterModuleDefinition(IScript::Module::moduledef_t* definition) = 0;
	virtual bool Shutdown() = 0;
	virtual ~IScriptKit() { }
protected:
	IScriptKit() { }
	IScriptKit(std::string& path) { }
	IScriptKit(const IScriptKit&) { }
	const IScriptKit& operator=(const IScriptKit& ref) { return ref; }
};

extern "C" SCRIPTKIT_API IScriptKit* GetEngine(std::string& path);

}

#endif /* __SCRIPTKIT_HPP__ */
